package cn.xiaoxiang.basic.service.impl;

import cn.xiaoxiang.aop1.PethomeAop;
import cn.xiaoxiang.basic.mapper.BaseMapper;
import cn.xiaoxiang.basic.query.BaseQuery;
import cn.xiaoxiang.basic.service.BaseService;
import cn.xiaoxiang.basic.util.PageList;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements BaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;
    @Override
    @PethomeAop(name = "这是全部查询方法")
    public List<T> findAll() {
        List<T> all = baseMapper.findAll();
        return all;
    }

    @Override
    @PethomeAop(name = "这是删除方法")
    public void delete(long id) {
        baseMapper.delete(id);
    }

    @Override
    @PethomeAop(name = "这是增加方法")
    public void add(T t) {
        baseMapper.add(t);
    }

    @Override
    @PethomeAop(name = "这是修改方法")
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    @PethomeAop(name = "这是单查询方法")
    public T findById(long id) {
        T byid = baseMapper.findById(id);
        return byid;
    }



    @Override
    @PethomeAop(name = "这是分页查询方法")
    public PageList<T> queryByPage(BaseQuery query) {
        Integer totals = baseMapper.queryByCount(query);
        if (null==totals||0==totals)
            return new PageList<>(0,new ArrayList<>());
        List<T> rows = baseMapper.queryByPage(query);
        return new PageList<>(totals,rows);
    }
    @Override
    @PethomeAop(name = "这是批量删除方法")
    public void batchdelete(List<Long> ids) {
        baseMapper.batchdelete(ids);
    }
}